class ComicSceneVO {
	public scene:string;
	public shot:string;

	public shots:ComicShotVO[];
	public roles:ComicRoleVO[];

	public dbData:string;
	public textureData:string;
	public texturePng:string;
	
	private _config:SceneConfig;

	public asset:DBConfig;

	public constructor(config:SceneConfig) {
		this._config = config;
		this.init();
	}
	public toString():string
	{
		return this._config.name
	}
	private init():void
	{
		this.roles = [];
		this.shots = [];
		this.asset = ComicResourceManager.instance.getArmatureAsset(this._config.name);
		this.dbData = this.asset.dbData;
		this.textureData = this.asset.textureData;
		this.texturePng = this.asset.texturePng;

		let i:number;
		let len:number;

		for(i = 0, len = this._config.roles.length; i < len; i++)
		{
			let role:ComicRoleVO = new ComicRoleVO(this._config.roles[i]);
			this.roles.push(role);
		}

		for(i = 0, len = this._config.shots.length; i < len; i++)
		{
			let shot:ComicShotVO = new ComicShotVO(this._config.shots[i]);
			shot.scene = this;
			this.shots.push(shot);
		}
		this.initShots();
	}

	public get name():string
	{
		return this._config.name;
	}
	public get startShot():ComicShotVO
	{
		return this.shots[0];
	}

	public initShots():void
	{
		let i:number;
		let len:number;
		for(i = 0, len = this.shots.length; i < len; i++)
		{
			if(this.shots[i].next)
			{
				this.shots[i].nextShots = [this.getShot(this.shots[i].next)];
			}
			else if(this.shots[i].selectNext && this.shots[i].selectNext.length > 0)
			{
				this.shots[i].nextShots = [];
				for(let j:number = 0, jlen:number = this.shots[i].selectNext.length; j < jlen; j++)
				{
					let shot = this.getShot(this.shots[i].selectNext[j])
					if(shot)
					{
						this.shots[i].nextShots.push(shot);
					}
				}
			}
			
		}
	}

	private getShot(name:string):ComicShotVO
	{
		let i:number;
		let len:number;
		for(i = 0, len = this.shots.length; i < len; i++)
		{
			if(this.shots[i].name == name)
			{
				return this.shots[i]
			}
		}
		return null;
	}

	public getRoleAssets():DBConfig[]
	{
		let dbs:DBConfig[] = [];
		let i:number;
		let len:number;
		for(i = 0, len = this.roles.length; i < len; i++)
		{
			let roleAsset = this.roles[i].asset;
			if(dbs.indexOf(roleAsset) == -1)
			{
				dbs.push(roleAsset);
			}
		}
		return dbs;
	}
	public getClothAssets():DBConfig[]
	{
		let dbs:DBConfig[] = [];
		let i:number;
		let len:number;
		let clothDBArr:string[] = [];
		for(i = 0, len = this.roles.length; i < len; i++)
		{
			let role = this.roles[i];
			if(role.suit)
			{
				let j:number;
				let jlen:number;
				for(j = 0, jlen = role.suit.clothes.length; j < jlen; j++)
				{
					let clothName = role.suit.clothes[j];
					let cloth:Cloth = ComicResourceManager.instance.getCloth(clothName);
					if(cloth)
					{
						if(clothDBArr.indexOf(cloth.data) == -1)
						{
							clothDBArr.push(cloth.data);
						}	
					}
				}
			}
		}
		if(clothDBArr.length > 0)
		{
			for(i = 0, len = clothDBArr.length; i < len; i++)
			{
				let dbConfig = ComicResourceManager.instance.getDragonBonesAsset(clothDBArr[i]);
				if(dbConfig)
				{
					dbs.push(dbConfig);
				}
			}
		}
		return dbs;
	}
}